const fs = require("fs");
const path = require("path");
const http = require("http");

const server = http.createServer((req, res) => {
    // res.end("ok");
    let {
        url
    } = req;

    let ext = url.slice(url.lastIndexOf("."));
    console.log(ext);

    if (url === "/" || url === "/index.html") {
        let file = fs.readFileSync(path.join(__dirname, "/index.html"), "utf8");
        res.end(file);
    } else if (ext === ".css") {
        let file = fs.readFileSync(path.join(__dirname, url));
        res.end(file);
    } else if (ext === ".jpg" || ext === ".png" || ext === '.jpeg') {
        let file = fs.readFileSync(path.join(__dirname, url));
        res.end(file)
    } else if (ext === ".js") {
        let file = fs.readFileSync(path.join(__dirname, url));
        res.end(file);
    } else if (ext === '.mp4') {
        res.setHeader("content-type", "video/mp4")
        let file = fs.readFileSync(path.join(__dirname, url));
        res.end(file);
    }

})

server.listen(8000, () => {
    console.log('server ok');
})